﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DTO;
using BUS;
namespace GUI
{
    public partial class frmNguyenLieuMonAn : Form
    {
        public frmNguyenLieuMonAn()
        {
            InitializeComponent();
        }

        private void frmNguyenLieuMonAn_Load(object sender, EventArgs e)
        {
            LoadMoAn();

        }

        void LoadMoAn()
        {
           
            AutoCompleteStringCollection auto = new AutoCompleteStringCollection();
            List<MonAnDTO> res = new List<MonAnDTO>();
            MonAnBUS bus = new MonAnBUS();
            res = bus.getDsMonAn();
            List<string> lis = new List<string>();
            
            for(int i=0;i<res.Count;i++)
            {
                lis.Add(res[i].MonAnId.ToString());
                lis.Add(res[i].TenMonAn);
            }

            for (int i = 0; i < lis.Count; i++)
                auto.Add(lis[i]);
            txtTimKiem.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            txtTimKiem.AutoCompleteSource = AutoCompleteSource.CustomSource;
            txtTimKiem.AutoCompleteCustomSource = auto;
        }
        string LayMaMonAn(string strmonan)
        {
            List<MonAnDTO> res = new List<MonAnDTO>();
            MonAnBUS bus = new MonAnBUS();
            res = bus.getDsMonAn();
            for (int i = 0; i < res.Count; i++)
            {
                if (res[i].MonAnId.ToString().CompareTo(strmonan) == 0 || res[i].TenMonAn.CompareTo(strmonan) == 0)
                {
                    return res[i].MonAnId.ToString();
                }
            }
            return null;
        }
        private void btTimKiem_Click(object sender, EventArgs e)
        {
            string monanid = LayMaMonAn(txtTimKiem.Text.Trim());
            if (monanid == null)
            {
                MessageBox.Show("Món Ăn '" + txtTimKiem.Text.Trim() + "' không tồn tại.");
                txtTimKiem.Focus();
                txtTimKiem.SelectAll();
                return;
            }

            lbTieude.Text = "Nguyên Vật Liệu:";
            lbMon.Text = "MÓN " + txtTimKiem.Text.Trim();

            List<NguyenVatLieuDTO> nvl = new List<NguyenVatLieuDTO>();
            NguyenVatLieuBUS bus = new NguyenVatLieuBUS();
            nvl = bus.LayDanhSachNguyenVatLieu();
            string temp="";
            for (int i = 0; i < nvl.Count; i++)
            {
                temp =temp + "- " + nvl[i].TenNGVL +"\n";
            }
            lbnvl.Text = temp;
        }
    }
}
